<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JSON格式字符串和JavaScript对象之间的转换</title>
</head>
<body>
    <script>
        //1、JSON格式字符串转换成JavaScript对象
        var jsonStr='{"name":"张三","age":25,"addr":["北京","上海","广州"]}';

        var jsObject=JSON.parse(jsonStr);
        console.log(jsObject.name);
        console.log(jsObject.age);
        console.log(jsObject.addr);


        //2、JavaScript对象转换成JSON格式字符串
        var jsonStr2=JSON.stringify(jsObject);
        console.log(jsonStr2);

    </script>
</body>
</html>